import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/21 16:25
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class Solution {

    static int index = 0;

    public boolean evaluateTree(TreeNode root) {
        if (root.left == null) {
            return root.val == 1;
        }

        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);

        return root.val == 2 ? (left || right) : (left && right);
    }

    public static TreeNode BuildTree(int[] nums) {
        if (nums == null || nums.length == 0) {
            return null;
        }

        Queue<TreeNode> queue = new LinkedList<>();
        TreeNode root = new TreeNode(nums[0]);
        queue.offer(root);

        int i = 1;
        while (!queue.isEmpty() && i < nums.length) {
            TreeNode currentNode = queue.poll();

            if (i < nums.length && nums[i] != -1) {
                currentNode.left = new TreeNode(nums[i]);
                queue.offer(currentNode.left);
            }
            i++;

            if (i < nums.length && nums[i] != -1) {
                currentNode.right = new TreeNode(nums[i]);
                queue.offer(currentNode.right);
            }
            i++;
        }

        return root;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            TreeNode root = BuildTree(nums);
            Solution solution = new Solution();
            System.out.println(solution.evaluateTree(root));
        }
    }
}